package com.lagou.task05;


import java.nio.channels.Pipe;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * 编程实现斗地主部分功能，要求如下：
 * 1.首先准备 54张扑克牌并打乱顺序。
 * 2.由三个玩家交替摸排，每人 17张扑克牌，最后三张留作底牌。
 * 3.查看三个玩家手中的扑克牌和底牌。
 * 4.其中玩家的扑克牌需要按照大小顺序打印，规则如下：  大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3
 *
 * */
public class PokerTest {

    public static void main(String[] args) {
        // 准备54张扑克牌
        List<Poker> allPoker = new LinkedList<>();
        // 所有数字
        String[] arr = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        // 排序flag
        int[] sortFlag = {12,13,1,2,3,4,5,6,7,8,9,10,11};
        // 所有花色
        String[] colorType = {"♥","♦","♠","♣"};

        // 生成扑克牌
        for (int i = 0; i < 13; i++) {
            String sNum = arr[i];
            for (String ct : colorType) {
                Poker p = new Poker(sNum,ct,sortFlag[i]);
                allPoker.add(p);
            }
        }

        //小王和大王 分别添加
        allPoker.add(new Poker("小王","B",14));
        allPoker.add(new Poker("大王","R",15));

        // 打印已生成的扑克牌
        for (Poker p : allPoker) {
            System.out.println("生成扑克牌：" + p);
        }

        //打乱顺序
        Collections.shuffle(allPoker);

        //声明三个玩家
        Player p1 = new Player("玩家一",new LinkedList<>());
        Player p2 = new Player("玩家二",new LinkedList<>());
        Player p3 = new Player("玩家三",new LinkedList<>());

        System.out.println();
        System.out.println("------------------开始轮流摸牌------------------");
        int order = 1; // 标记次序。1：玩家一  2：玩家二  3：玩家三
        //int i = 0;
        //三个玩家轮流摸牌
        while (allPoker.size() > 3){
            Poker p = allPoker.get(0);
            if (1 == order){
                p1.getPoker(p);
                order++;
            }else if (2 == order){
                p2.getPoker(p);
                order++;
            }else{
                p3.getPoker(p);
                order = 1;
            }
            allPoker.remove(p);
            //i++;
        }
        System.out.println("------------------摸牌结束------------------");
        System.out.println();

        //查看三个玩家的手牌
        p1.show();
        p2.show();
        p3.show();

        //打印底牌
        System.out.println("剩余底牌：");
        for (Poker p : allPoker) {
            System.out.println(p);
        }


    }
}
